import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _isFunction from "lodash/isFunction";
import _forEach from "lodash/forEach";

var _dec, _class;

/**
 * ComponentProp.js
 * @date 2018-10-02
 */
import React from 'react';
import { Divider, Form, Input
/* , Checkbox as CpaasCheckbox */
, InputNumber } from 'antd';
import intl from 'utils/intl';
import { attributeNameProp, attributeValueProp } from "../../config";
var inputComponentStyle = {
  width: '100%'
};
var ComponentProp = (_dec = Form.create({
  fieldNameProp: null,
  onValuesChange: function onValuesChange(props, changedValues, allValues) {
    if (_isFunction(props.onValuesChange)) {
      props.onValuesChange(props, changedValues, allValues);
    }
  }
}), _dec(_class = /*#__PURE__*/function (_React$Component) {
  _inherits(ComponentProp, _React$Component);

  var _super = _createSuper(ComponentProp);

  function ComponentProp() {
    _classCallCheck(this, ComponentProp);

    return _super.apply(this, arguments);
  }

  _createClass(ComponentProp, [{
    key: "render",
    value: function render() {
      var component = this.props.component;
      var propValues = {};

      _forEach(component.config, function (prop) {
        propValues[prop[attributeNameProp]] = prop[attributeValueProp];
      });

      return /*#__PURE__*/React.createElement(Form, null, this.renderComponentCommonProps(propValues), /*#__PURE__*/React.createElement(Divider, null), this.renderComponentDynamicToolbarProps(propValues));
    }
  }, {
    key: "renderComponentCommonProps",
    value: function renderComponentCommonProps() {
      var _this$props = this.props,
          form = _this$props.form,
          component = _this$props.component;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form.Item, {
        key: "templateCode",
        label: intl.get('cpfm.ui.model.template.code').d('编码')
      }, form.getFieldDecorator('templateCode', {
        initialValue: component.templateCode,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validate.notNull', {
            name: intl.get('cpfm.ui.model.template.code').d('编码')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, {
        disabled: true
      }))), /*#__PURE__*/React.createElement(Form.Item, {
        key: "description",
        label: intl.get('cpfm.ui.model.template.description').d('名称')
      }, form.getFieldDecorator('description', {
        initialValue: component.description,
        rules: [{
          required: true,
          message: intl.get('cpaas.common.validate.notNull', {
            name: intl.get('cpfm.ui.model.template.description').d('名称')
          })
        }]
      })( /*#__PURE__*/React.createElement(Input, null))));
    }
  }, {
    key: "renderComponentDynamicToolbarProps",
    value: function renderComponentDynamicToolbarProps(propValues) {
      var form = this.props.form;
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Form.Item, {
        key: "styleMarginBottom",
        label: intl.get('cpfm.ui.model.style.marginBottom').d('下间距')
      }, form.getFieldDecorator('style.marginBottom', {
        initialValue: propValues['style.marginBottom']
      })( /*#__PURE__*/React.createElement(InputNumber, {
        style: inputComponentStyle
      }))));
    }
  }]);

  return ComponentProp;
}(React.Component)) || _class);

if (process.env.NODE_ENV === 'production') {
  ComponentProp.displayName = 'DynamicToolbar(ComponentProp)';
}

export default ComponentProp;